package iteratorbind.impl;

import iteratorbind.base.ArrayMenuIterator;
import iteratorbind.base.BaseMenu;
import iteratorbind.entity.MenuItem;
import java.util.Iterator;

/**
 * 女招待对象
 * @author yaojianfeng
 */
public class Waitress {
    private BaseMenu menuItemArray;
    private BaseMenu menuItemArrayList;
    private BaseMenu menuItemHashMap;

    public Waitress(BaseMenu menuItemArray, BaseMenu menuItemArrayList,BaseMenu menuItemHashMap) {
        this.menuItemArray = menuItemArray;
        this.menuItemArrayList = menuItemArrayList;
        this.menuItemHashMap = menuItemHashMap;
    }

    /**
     * 暴露出的迭代方法
     * 内部还是用的迭代器
     */
    public void printMenu(){

        Iterator iterator2 = menuItemHashMap.getIterator();
        printMenu(iterator2);
        System.out.println("7777777777777777777777777777777777777777777");

        Iterator iterator1 = menuItemArrayList.getIterator();
        printMenu(iterator1);
        System.out.println("8888888888888888888888888888888888888888888");

        ArrayMenuIterator iterator = (ArrayMenuIterator) menuItemArray.getIterator();
        printMenu(iterator);
        System.out.println("9999999999999999999999999999999999999999999");
    }

    /**
     * 使用迭代器进行迭代
     * @param iterator 迭代器接口
     */
    private void printMenu(Iterator iterator){
        while (iterator.hasNext()){
            MenuItem next = (MenuItem) iterator.next();
            System.out.println(next.getName());
            System.out.println(next.getDescription());
            System.out.println(next.getPrice());
        }

    }
}
